﻿Chenxin.UI.IncomeDetails = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/Reports/IncomeDetails.ashx',
    createSearch: function() {
        return new Chenxin.UI.IncomeDetailsSearch({
            scope: this
        });
    },
    createGrid: function() {
        _this = this;
        return new Chenxin.UI.ReportGrid({
            actionUrl: this.actionUrl + '?op=getlist',
            pageSize: 100,
            hasTotal: false,
            hasPage: true,
            cellBorder: true,
            height: 400,
            renderTo: 'divShowBalanceList',
            hasCheckBox: false,
            id: 'DepartId',
            title: '实收汇总明细表',
            autoLoad: false,
            scope: this,
            createTitleTool: function() {
                return [{
                    text: '<span id="" class="x-grid-export" style="width:90px" title="导出全部数据">导出全部数据</span>',
                    scope: this,
                    title: '导出全部数据',
                    handler: function(el) {
                        _this.exportAll();
                    }
}];
                },
                columns: {
                    business: { head: '商圈', width: 100, sortable: true, captionCol: true },
                    departname: { head: '门店', width: 100, sortable: true, inTotal: false },
                    Employee: { head: '业务员', width: 100, sortable: true, inTotal: false },
                    ContractCode: { head: '成交编号', width: 150, sortable: true, inTotal: false },
                    ContractDate: { head: '成交日期', width: 100, sortable: true, inTotal: false,
                        renderer: function(val, c, row) {
                            if (val.length > 0)
                                return val.split(' ')[0];
                            else
                                return '';
                        }
                    },
                    HouseAddress: { head: '地址', width: 240, sortable: true, inTotal: false },
                    typetime: { head: '时间归属', width: 50, sortable: true, inTotal: false,
                        renderer: function(val, c, row) {
                            if (val == '10')
                                return '本期';
                            else if (val == '20')
                                return '前期';
                            else
                                return '';
                        }
                    },
                    realget: { head: '本次实际收/付', width: 100, sortable: true, inTotal: false },
                    point: { head: '点数', width: 100, sortable: true, inTotal: false },
                    zget: { head: '分摊实收金额', width: 100, sortable: true },
                    fget: { head: '分摊实付金额', width: 100, sortable: true },
                    sum: { head: '合计', width: 100, sortable: true, inTotal: false,
                        renderer: function(val, c, row) {
                            if (row.zget)
                                return row.zget;
                            else
                                return row.fget;
                        }
                    },
                    BargainCompanyName: { head: '归属公司', width: 100, sortable: true, inTotal: false }
                }
            });
        },
        exportAll: function() {
            _this = this;
            paramStr = this.search.getParamJson();
            paramStr.op = 'exportAll';
            Chenxin.Msg.Waiting.show();
            Chenxin.Fn.exportToExcelByServer(this.actionUrl, paramStr, '导出文件');
            //$.ajax({ url: this.actionUrl, data: paramStr,async:false});
            Chenxin.Msg.Waiting.hide();
        }
    });

/*
* 查询面板
*/
Chenxin.UI.IncomeDetailsSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'divCondition',
    createComboList: function() {
		
        //人员
        this.comboUserId = new Chenxin.UI.RichModelTreeCombo({
            textBoxId: 'txtUser',
            inModelType: 'all',
            txtModelName: 'UserName',
            singleSelect: true,
            name: 'UserId'
        });
		
		var _this=this;
        this.combl = new Chenxin.UI.StructComboList({
            cityAfterSelected: function() {
                _this.comboUserId.reset();
            },
            companyAfterSelected: function() {
                _this.comboUserId.reset();
            },
            businessDistrictAfterSelected: function() {
                _this.comboUserId.reset();
            },
            departsAfterSelected: function(val) {
                _this.comboUserId.reset();
                if (val != '请选择') {
                    _this.comboUserId.loadUser(val, 500);
                }
            }
        });
        var structs = this.combl.comboList;
        structs.push(this.comboUserId);

        return structs;
    },
    initEvent: function() {
        $("#txtStartTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        }).defText({
            deftxt: '开始时间'
        });

        $("#txtEndTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        }).defText({
            deftxt: '结束时间'
        });

        var curdate = new Date();
        $('#txtActualDate').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1));
		
        $("#txtActualDate").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
		
        $("#txtKeyword").defText({
            deftxt: '成交编号/房源地址'
        });
		
		$('.x_type').bind('click',{scope:this},function(e){
			var fn=this.value=='10'?'setEnable':'setDisable';
			e.data.scope.combl.businessDistrict[fn]();
			e.data.scope.combl.departs[fn]();
			e.data.scope.comboUserId[fn]();
			
			e.data.scope.combl.businessDistrict.reset();
			e.data.scope.combl.departs.reset();
			e.data.scope.comboUserId.reset();
		});

        var objSrh = this;
        /*********事件：检索按钮*********/
        $("#btSearch").click(function() {
            objSrh.scope.reloadGrid();
        });
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(function() {
    var objPg = new Chenxin.UI.IncomeDetails();
});